bitkeeper revision 1.1159.257.1 (420a5d09baXJPJiifdfGaELY297KOw)
authoriap10@freefall.cl.cam.ac.uk <iap10@freefall.cl.cam.ac.uk>
Wed, 9 Feb 2005 18:57:13 +0000 (18:57 +0000)
committeriap10@freefall.cl.cam.ac.uk <iap10@freefall.cl.cam.ac.uk>
Wed, 9 Feb 2005 18:57:13 +0000 (18:57 +0000)
Refactor code to eliminate some code duplication.
- added gva_to_gpte
- gva_to_gpa uses gva_to_gpte now
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
Signed-off-by: ian.pratt@cl.cam.ac.uk
xen/arch/x86/vmx.c
xen/arch/x86/vmx_platform.c
xen/include/asm-x86/shadow.h
xen/include/asm-x86/vmx_platform.h

index 70e669183fb84e33bdb5ca5446a08a08f9ffe564..01bc3720415af75e8b843528cdcdc48a92cb8de5 100644 (file)
@@ -109,11 +109,9 @@ static void inline __update_guest_eip(unsigned long inst_len)
 
 static int vmx_do_page_fault(unsigned long va, unsigned long error_code) 
 {
-    unsigned long eip, pfn;
-    unsigned int index;
-    unsigned long gpde = 0, gpte, gpa;
+    unsigned long eip;
+    unsigned long gpa;
     int result;
-    struct exec_domain *ed = current;
 
 #if VMX_DEBUG
     {
@@ -123,32 +121,13 @@ static int vmx_do_page_fault(unsigned long va, unsigned long error_code)
                 va, eip, error_code);
     }
 #endif
-    /*
-     * Set up guest page directory cache to make linear_pt_table[] work.
-     */
-    __guest_get_l2e(ed, va, &gpde);
-    if (!(gpde & _PAGE_PRESENT))
-        return 0;
-
-    index = (va >> L2_PAGETABLE_SHIFT);
-    if (!l2_pgentry_val(ed->arch.guest_pl2e_cache[index])) {
-        pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT);
 
-        VMX_DBG_LOG(DBG_LEVEL_VMMU, "vmx_do_page_fault: pagetable = %lx\n",
-                pagetable_val(ed->arch.pagetable));
-
-        ed->arch.guest_pl2e_cache[index] = 
-            mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
-    }
-    
-    if (unlikely(__get_user(gpte, (unsigned long *)
-                            &linear_pg_table[va >> PAGE_SHIFT])))
+    gpa = gva_to_gpa(va);
+    if (!gpa)
         return 0;
-    
-    gpa = (gpte & PAGE_MASK) | (va & (PAGE_SIZE - 1));
 
     if (mmio_space(gpa))
-        handle_mmio(va, gpte, gpa);
+        handle_mmio(va, gpa);
 
     if ((result = shadow_fault(va, error_code)))
         return result;
@@ -299,35 +278,6 @@ static inline void guest_pl2e_cache_invalidate(struct exec_domain *ed)
     memset(ed->arch.guest_pl2e_cache, 0, PAGE_SIZE);
 }
 
-inline unsigned long gva_to_gpa(unsigned long gva)
-{
-    unsigned long gpde, gpte, pfn, index;
-    struct exec_domain *ed = current;
-
-    __guest_get_l2e(ed, gva, &gpde);
-    index = (gva >> L2_PAGETABLE_SHIFT);
-
-    pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT);
-
-    ed->arch.guest_pl2e_cache[index] = 
-            mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
-
-    if ( unlikely(__get_user(gpte, (unsigned long *)
-                             &linear_pg_table[gva >> PAGE_SHIFT])) )
-    {
-        printk("gva_to_gpa EXIT: read gpte faulted" );
-        return 0;
-    }
-
-    if ( !(gpte & _PAGE_PRESENT) )
-    {
-        printk("gva_to_gpa - EXIT: gpte not present (%lx)",gpte );
-        return 0;
-    }
-
-    return (gpte & PAGE_MASK) + (gva & ~PAGE_MASK); 
-}
-
 static void vmx_io_instruction(struct xen_regs *regs, 
                    unsigned long exit_qualification, unsigned long inst_len) 
 {
index 284243eca1e92b01a8c8d57d1d124b9b428cf928..2f4d4ed21a1c60ae3df92af5bfe2be078dab39c5 100644 (file)
@@ -378,12 +378,7 @@ static int inst_copy_from_guest(char *buf, unsigned long guest_eip, int inst_len
     }
 
     if ((guest_eip & PAGE_MASK) == ((guest_eip + inst_len) & PAGE_MASK)) {
-        if ( unlikely(__get_user(gpte, (unsigned long *)
-                                 &linear_pg_table[guest_eip >> PAGE_SHIFT])) )
-            {
-                printk("inst_copy_from_guest- EXIT: read gpte faulted" );
-                return 0;
-            }
+        gpte = gva_to_gpte(guest_eip);
         mfn = phys_to_machine_mapping(gpte >> PAGE_SHIFT);
         ma = (mfn << PAGE_SHIFT) | (guest_eip & (PAGE_SIZE - 1));
         inst_start = (unsigned char *)map_domain_mem(ma);
@@ -392,6 +387,7 @@ static int inst_copy_from_guest(char *buf, unsigned long guest_eip, int inst_len
         unmap_domain_mem(inst_start);
     } else {
         // Todo: In two page frames
+        BUG();
     }
         
     return inst_len;
@@ -432,7 +428,6 @@ static void send_mmio_req(unsigned long gpa,
     ioreq_t *p;
     struct mi_per_cpu_info *mpci_p;
     struct xen_regs *inst_decoder_regs;
-    extern inline unsigned long gva_to_gpa(unsigned long gva);
     extern long evtchn_send(int lport);
     extern long do_block(void);
 
@@ -476,7 +471,7 @@ static void send_mmio_req(unsigned long gpa,
 
 }
 
-void handle_mmio(unsigned long va, unsigned long gpte, unsigned long gpa)
+void handle_mmio(unsigned long va, unsigned long gpa)
 {
     unsigned long eip;
     unsigned long inst_len;
index f5bc010415e31815c53662fda7b7f0c69dda6584..15858d5901521622cd394e07ddea8c60573699b3 100644 (file)
@@ -684,6 +684,41 @@ static inline void vmx_update_shadow_state(
     unmap_domain_mem(mpl2e);
 }
 
+static inline unsigned long gva_to_gpte(unsigned long gva)
+{
+    unsigned long gpde, gpte, pfn, index;
+    struct exec_domain *ed = current;
+
+    __guest_get_l2e(ed, gva, &gpde);
+    if (!(gpde & _PAGE_PRESENT))
+        return 0;
+
+    index = (gva >> L2_PAGETABLE_SHIFT);
+
+    if (!l2_pgentry_val(ed->arch.guest_pl2e_cache[index])) {
+        pfn = phys_to_machine_mapping(gpde >> PAGE_SHIFT);
+        ed->arch.guest_pl2e_cache[index] = 
+            mk_l2_pgentry((pfn << PAGE_SHIFT) | __PAGE_HYPERVISOR);
+    }
+
+    if ( unlikely(__get_user(gpte, (unsigned long *)
+                             &linear_pg_table[gva >> PAGE_SHIFT])) )
+        return 0;
+
+    return gpte;
+}
+
+static inline unsigned long gva_to_gpa(unsigned long gva)
+{
+    unsigned long gpte;
+
+    gpte = gva_to_gpte(gva);
+    if ( !(gpte & _PAGE_PRESENT) )
+        return 0;
+
+    return (gpte & PAGE_MASK) + (gva & ~PAGE_MASK); 
+}
+
 #endif /* CONFIG_VMX */
 
 static inline void __shadow_mk_pagetable(struct exec_domain *ed)
index 63cb74d90f341ca52ebf718838b9d2aabe2a791c..83cbb59e6f37da778d172cfa6b1913dddd1b3d02 100644 (file)
@@ -86,7 +86,7 @@ struct virutal_platform_def {
     struct mi_per_cpu_info mpci;            /* MMIO */
 };
 
-extern void handle_mmio(unsigned long, unsigned long, unsigned long);
+extern void handle_mmio(unsigned long, unsigned long);
 extern int vmx_setup_platform(struct exec_domain *, execution_context_t *);
 
 static inline int mmio_space(unsigned long gpa)